<!DOCTYPE html>
<html>
<head>
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
            <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
            <link rel="stylesheet" type="text/css" href="../../css/aui.css">
            <link rel="stylesheet" type="text/css" href="../../css/aui-slide.css">
            <link rel="stylesheet" type="text/css" href="../../css/api.css">
            <script type="text/javascript" src="../../script/api.js"></script>
</head>
    <style>
        html {
            font-size: 40%;
            height: 100%;
            width: 100%;
            display: table;
        }

        body {
            display: table-cell;
            width: 100%;
            height: 100%;
        }
        ul{
            margin: 0;
            padding: 0;
        }
        li{
            list-style: none;
        }
        .all{
            height: 100%;
            width: 100%;
        }
        .top{
            position: relative;
            background-color: #f7911b;
            height:7rem;
            width: 100%;
            text-align: center;
        }
        .back{
            font-size: 6rem;
            color: white;
            left: 2rem;
            line-height: 6.5rem;
            position: absolute;
        }
        .title{
            font-size: 3rem;
            color: white;
            line-height: 6.5rem;
            float: left;
            margin-left: 13rem;
        }
        .add{
            font-size: 2.5rem;
            color: white;
            position: absolute;
            right: 2rem;
            top: 1.5rem;
        }
        .add img{
            float: left;
            margin-top: 0.4rem;
        }
        .main{
            position: absolute;
            height: 92.32%;
            width: 100%;
            background-color: #f6f6f6;
            overflow: auto;
        }
        .address_item{
            width: 100%;
            background-color: white;
            height: 14rem;
            margin-top: 1rem;
        }
        .defau_box{
            width: 6rem;
            height: 3rem;
            color: white;
        }
        .defau .defau_box{
            background-color: red;
            width: 6rem;
            height: 3rem;
            color: white;
            display: block;
            font-size: 2rem;
            border-bottom-right-radius: 0.8rem;
            border-top-right-radius: 0.8rem;
        }
        .defau .defau_box span{
            float: right;
            margin-right: 1rem;
            margin-top: 0.6rem;
        }
        .info_item{
            width: 28rem;
            height: 10rem;
            margin-top: 1rem;
            margin-left: 2rem;
            float: left;
        }
        .add_name{
            display: block;
            width: 30%;
            font-size: 2.4rem;
            color: #666666;
            float: left;
        }
        .add_tel{
            display: block;
            width: 70%;
            font-size: 2.4rem;
            color: #666666;
            float: left;
        }
        .add_address{
            display: block;
            font-size: 2.4rem;
            color: #666666;
            float: left;
            margin-top: 1.5rem;
        }
        .upd_btn{
            height: 100%;
            width: 14rem;
            float: right;
            margin-top: -3rem;
            border-left: 0.1rem solid #CCC;
        }
        .upd_btn span{
            display: block;
            font-size: 2.8rem;
            margin: auto;
            text-align: center;
            margin-top: 6rem;
        }
    </style>
</head>
<body>
<div class="all">
    <div class="top">
        <span class="aui-iconfont aui-icon-left" style="font-size: 3rem;float:left;margin-top: 2rem;margin-left:0.7rem;" onclick="api.closeWin()"></span>
        <span class="title" style="line-height:7rem;margin-left: 15rem">编辑地址</span>
        <div  class="add"><img src="../../image/add.png" style="height:3rem;width:3rem;"/><span style="margin-top: 0.6rem;float: right;"  onclick="opanaddress()">&nbsp;添加</span></div>
    </div>
    <div class="main" id='main'>
        
        
    </div>
</div>
</body>

<script type="text/javascript">
    apiready = function() {
        api.addEventListener({
                name:'address'
            },function(ret,err){
                window.location.reload();
            });

        var token = $api.getStorage('token');
 	var token = {
                token: token,
                do:'sel'
            };
        api.ajax({
            url: 'http://www.mk517.com/webApi/address_list.php',
            method: 'post',
            "headers": {
                "Content-Type": "application/json"
            },
            dataType: "json",
            data: {
                body: token
            }
        }, function(ret, err) {
            // alert(JSON.stringify(ret));
            if (ret) {

                if (ret!=''||ret==undefined){
                    for(var i=0;i <= ret.data.length;i++ ){
                        if(ret.data[i]['is_default']==1){
                            var  id=ret.data[i]['id'];
                           
                            
                        $api.byId('main').innerHTML +='<div class="address_item defau">'+
                        '<div class="defau_box">'+
                        '<span>默认</span>'+
                        '</div>'+
                        '<div class="info_item">'+
                        '<span class="add_name">'+ret.data[i]['name']+'</span>'+
                       ' <span class="add_tel">手机号:'+ret.data[i]['tel']+'</span>'+
                        '<span class="add_address">地址:'+ret.data[i]['address']+'</span>'+
                        '</div>'+
                        '<div class="upd_btn">'+
                        '<span onclick="bianji('+id+')">编辑</span>'+
                        '</div>'+
                        '</div>'

                        }else{
                            var  id=ret.data[i]['id'];

                            $api.byId('main').innerHTML +='<div class="address_item ">'+
                        '<div class="defau_box">'+
                        '<span>默认</span>'+
                        '</div>'+
                        '<div class="info_item">'+
                        '<span class="add_name">'+ret.data[i]['name']+'</span>'+
                       ' <span class="add_tel">手机号:'+ret.data[i]['tel']+'</span>'+
                        '<span class="add_address">地址:'+ret.data[i]['address']+'</span>'+
                        '</div>'+
                        '<div class="upd_btn">'+
                        '<span onclick="bianji('+id+')">编辑</span>'+
                        '</div>'+
                        '</div>'


                        }


                    }
                }else{
                    alert("暂无数据");
                }
            //     var i=0;
            //   ret.data[i]['name']
            //   ret.data[i]['tel']
            //   ret.data[i]['address']
            //   ret.data[i]['is_default']
              
            //   $api.byId('fanli_tixing').innerHTML
                
             }else {
                alert(JSON.stringify(ret));
            }
        
        });

window.bianji =function(id){
    var num=1;
$api.setStorage('id',id);
var me=$api.getStorage('id');
$api.setStorage('bianji',num);
var token = $api.getStorage('token');
 	var token = {
                token: token,
                id:me,
                bianji:num
            };
    api.openWin({
               name: 'opanupd',
               url: 'address.html',
               rect: {
                   x: 0,
                   y: 0,
                   w: 'auto',
                   h: 'auto'
               },
               pageParam: {
                  body: token,
                  
                  
               },
               allowEdit: true
           });
        //    api.sendEvent(
        //               {
        //                 name:'aadress',
        //                 extra:{
        //                     key1:'ok',
        //                     key2:'ss'
        //                 }
        //               }
        //           );

    // var token = $api.getStorage('token');
 	// var token = {
    //             token: token,
    //             do:'upd'
    //         };
    //     api.ajax({
    //         url: 'http://www.mk517.com/webApi/mingxi.php',
    //         method: 'post',
    //         "headers": {
    //             "Content-Type": "application/json"
    //         },
    //         dataType: "json",
    //         data: {
    //             body: token
    //         }
    //     }, function(ret, err) {
    //         // alert(JSON.stringify(ret));
    //         if (ret) {
    //           console.log(ret);
                
    //          }else {
    //             alert(JSON.stringify(err));
    //         }
    //     });

}

        window.opanaddress = function() {
               
    //     var token = $api.getStorage('token');
 	// var token = {
    //             token: token,
    //             do:'add',
                
    //         };
    //     api.ajax({
    //         url: 'http://www.mk517.com/webApi/address_list.php',
    //         method: 'post',
    //         "headers": {
    //             "Content-Type": "application/json"
    //         },
    //         dataType: "json",
    //         data: {
    //             body: token
    //         }
    //     }, function(ret, err) {
    //         // alert(JSON.stringify(ret));
    //         if (ret) {
    //             alert(ret.default);
    var token = $api.getStorage('token');
    var num=0;
    $api.setStorage('bianji',num);
 	var token = {
                token: token,
                bianji:num
            };
               api.openWin({
               name: 'opanadd',
               url: 'address.html',
               rect: {
                   x: 0,
                   y: 0,
                   w: 'auto',
                   h: 'auto'
               },
               pageParam: {
                   body: token
               },
               allowEdit: true
           });
        // }else{

        // }
        // })

    }
    
        


    }
    </script>
</html>